<?
 class lang extends add_module{  function get_message_module(){   $lang_m=array();
   $lang=$this->model->get_message_module();

   foreach($lang as $key=>$value){    $lang_m[$value['name_message']]=$value['text'];
   }
   return $lang_m;
  }
  function _choose_standby(){   if(empty($_SERVER['HTTP_REFERER']))$this->default_lang();   return $this->show_table_lang();
  }

   function _choose_schedule(){   return $this->show_table_lang();
  }

  function show_table_lang(){   $tmp=$this->model->return_count_lang();
   if (!empty($tmp) && count($tmp)>=2){
    foreach($tmp as $key=>$value){     if($value['name']==$_SESSION['lang']){     	$ret.=$this->view->view("templates/site/tpl_module/lang/lang_link_!.tpl",$value,true);
      }else{     	$ret.=$this->view->view("templates/site/tpl_module/lang/lang_link.tpl",$value,true);
      }
    }
    $data['lang_link']=$ret;
    $data=$this->view->view("templates/site/tpl_module/lang/lang_form.tpl",$data,true);
    return $data;
    }else{   	 return $data="";
   	}
  }

  function choose($lang){  	$lang=$this->security($lang,2,3);
  	if(empty($lang)){     $this->default_lang();
  	 }else{  	  session_start();
      session_register("lang");
      $_SESSION['lang']=$lang;
      header("location:".$_SERVER['HTTP_REFERER']);
     }
  }
  protected function default_lang(){  	if(empty($_SESSION['lang'])){  	session_start();
    session_register("lang");
    $lang=$this->model->get_info("name","lang","default_lang","true");
    $_SESSION['lang']=$lang;
    }
  }



  protected function show_all_lang(){   $lang=$this->model->get_info("name","lang","default_lang","true");   $tmp=$this->model->return_count_lang();
   if(!empty($tmp)){    foreach($tmp as $key=>$value){     $value['l_ch_def_td']="&bull;";
     if($lang != $value['name'])$value['l_ch_def_td']=$this->view->view("templates/admin/lang/lang_body_tr_def.tpl",$value,true);     $ret.=$this->view->view("templates/admin/lang/lang_body_tr.tpl",$value,true);

    }
     return $ret;
    }else{   	 return false;
   	}
  }

  protected function get_lang(){   return $this->model->return_count_lang();
  }

  protected function chose_def($id){  	$this->model->save_def_lang($id);
  }

  protected function save_lang_info($id){   $this->security("POST");   $this->model->save_lang_info($id,$_POST['id'],$_POST['name'],$_POST['alias']);
  }

  protected function add_lang(){   $this->security("POST");
   $this->model->add_lang($_POST['name'],$_POST['alias']);
  }

  protected function del_lang($id){   $this->model->del_lang($id);
  }

  protected function choose_options(){  	$data['body_lang']=$this->show_all_lang();
    if(empty($data['body_lang']))$data['lang_all']="Empty lang";
   return $this->view->view("templates/admin/lang/lang.tpl",$data,true);
  }

  protected function return_all_lang_array(){   return $this->model->return_all_lang_array();
  }

  protected function return_last_Ilang(){  return $this->model->return_last_Ilang();
  }


 }
?>